package com.ra.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ra.dao.DealDAO;
import com.ra.model.deal.Deal;

//@Controller
public class DealController {

	private static final Logger log = Logger.getLogger(DealController.class);

//	@Autowired
	private DealDAO dealDAO;

	@RequestMapping("/newDeal.html")
	public ModelAndView newDeal(HttpServletRequest request, HttpServletResponse response) throws ServletException {

		ModelAndView modelAndView = new ModelAndView("deals/createDeal");
		log.debug("DealController :: addDeal :: Start");
		Deal d = new Deal();
		d.setDealSlabs(null);
		List<Deal> deals = new ArrayList<Deal>();
		deals.add(d);

		log.debug("DealController :: addDeal :: End");
		// loading the lookup values
		modelAndView.addObject("deal", d);

		return modelAndView;
	}

	@RequestMapping("/saveDeal.html")
	public void saveDeal(HttpServletRequest request, @ModelAttribute("deal") Deal deal) {
		log.info("saveDeal :: saving deal");
		dealDAO.save(deal);
		log.info("saveDeal :: saved successfully");
	}

	public DealDAO getDealDAO() {
		return dealDAO;
	}

	public void setDealDAO(DealDAO dealDAO) {
		this.dealDAO = dealDAO;
	}

}
